﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using System;
using System.ComponentModel;

#endregion

namespace InterLinq.Test {
	/// <summary>
	/// represents a order position within a <see cref="Order"/>
	/// </summary>
	[Serializable]
	public class WPFOrderPosition : INotifyPropertyChanged, IOrderPosition {
		#region Public Properties

		/// <summary>
		/// Get or sets the id
		/// </summary>
		public virtual Guid Id { get; set; }

		/// <summary>
		/// Gets the product of this order position
		/// </summary>
		public virtual IProduct Product {
			get { return m_product; }
			set {
				m_product = value;
				if (PropertyChanged != null) {
					PropertyChanged(this, new PropertyChangedEventArgs("Product"));
				}
			}
		}

		/// <summary>
		/// gets the how many article of the <see cref="Product"/> are sold
		/// </summary>
		public virtual int Count {
			get { return m_count; }
			set {
				m_count = value;
				if (PropertyChanged != null) {
					PropertyChanged(this, new PropertyChangedEventArgs("Count"));
				}
				if (CountChanged != null) {
					CountChanged(this, EventArgs.Empty);
				}
			}
		}

		#endregion

		#region Public Methods

		/// <summary>
		/// ctr
		/// </summary>
		/// <param name="count">how many of the given product is sold</param>
		/// <param name="product">the product</param>
		public WPFOrderPosition(int count, IProduct product) {
			Product = product;
			Count = count;
		}

		/// <summary>
		/// ctr
		/// </summary>
		public WPFOrderPosition() {
		}

		#endregion

		#region Public Fields

		public virtual event EventHandler CountChanged;

		#endregion

		#region Private Fields

		private int m_count;
		private IProduct m_product;

		#endregion

		#region INotifyPropertyChanged Members

		public virtual event PropertyChangedEventHandler PropertyChanged;

		#endregion
	}
}